<template>
  <el-form ref="form" :model="LoginForm" label-width="80px">
    <el-form-item label="用户名">
      <el-input v-model="LoginForm.username"></el-input>
    </el-form-item>
    <el-form-item label="密码">
      <el-input type="password" v-model="LoginForm.password"></el-input>
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="login()">立即创建</el-button>
      <el-button>取消</el-button>
    </el-form-item>
  </el-form>
</template>




<script>
  export default {
    data(){
      return{
        LoginForm:{
          username:'admin',
          password:'123456'
        }
      }
    },

    created() {
      // this.login()//回调地址
    },
    methods:{
      async login() {
        //get
        // this.$ajax.get('http://121.4.96.134:8086/api/login/login',{params:this.LoginForm})
        //post
       // var res = this.$ajax.post('http://121.4.96.134:8086/api/login/login',this.LoginForm)
       const {data:res} = await this.$ajax.post('http://121.4.96.134:8086/api/login/login',this.LoginForm)
        if (res.code == 0) {
          this.$msg.success(res.msg);
          // 将前端返回来的token存入session
          window.sessionStorage.setItem('token', res.token);

          //跳转到后台首页
          this.$router.push('/')

        } else {
          this.$msg.error(res.msg);
        }


        // console.log(res)
      },
    }
  }
</script>


<style>

</style>